class Solution
{
public:
    long long repairCars(vector<int> &ranks, int cars)
    {
        auto checkAnswer = [&](long long x)
        {
            long long sum = 0;
            for (auto rank : ranks)
            {
                sum += floor(sqrt(static_cast<double>(x) / rank));
            }
            return sum >= cars;
        };

        long long l = 0, r = 1e15;
        while (l < r)
        {
            long long mid = (l + r) >> 1;
            if (checkAnswer(mid))
            {
                r = mid;
            }
            else
            {
                l = mid + 1;
            }
        }
        return l;
    }
};